package com.example.javamaday.leetcode;

import com.example.javamaday.leetcode.base.TreeNode;

public class LeetCodeTest0701 {

    public static void main(String[] args) {

    }

    public TreeNode insertIntoBST(TreeNode root, int val) {
        if (root == null) {
            return new TreeNode(val);
        }
        TreeNode curNode = root;
        while (true) {
            if (curNode.val < val) {
                if (curNode.right == null) {
                    curNode.right = new TreeNode(val);
                    break;
                } else {
                    curNode = curNode.right;
                }
            } else {
                if (curNode.left == null) {
                    curNode.left = new TreeNode(val);
                    break;
                } else {
                    curNode = curNode.left;
                }
            }
        }
        return root;
    }
}
